#include "background.h"

bool background::instance = false;
background *background::back= NULL;

//int HEIGHT = 22;
//int WEIGHT = 22;

void background::backgroundToLoad()
{
	/*bckgrnd = IMG_Load("resources/background.png");*/
	SDL_Surface* loadImage = IMG_Load("resources/background.png");
	bckgrnd = NULL;
	if( loadImage != NULL )
    {
        bckgrnd = SDL_DisplayFormat( loadImage );
        SDL_FreeSurface( loadImage );
        if( bckgrnd != NULL )
        {
            //Color key surface
            SDL_SetColorKey( bckgrnd, SDL_SRCCOLORKEY, SDL_MapRGB( bckgrnd->format, 255, 0, 255 ) );
        }
    }
	if(bckgrnd==NULL)
	{
		printf("No background image loaded\n");
		printf("Could not open");
	}
}

void background::draw(SDL_Surface *screen)
{
	int i,j;
	for(i=0;i<22;i++){
		this->offset.y = HEIGHT * i;
		for(j=0;j<30;j++){
			this->offset.x = WEIGHT * j;
			SDL_BlitSurface(this->bckgrnd,NULL,screen,&this->offset);
		}
	}
	//SDL_BlitSurface(this->bckgrnd,NULL,screen,&this->offset);
}

void background::update(SDL_Surface *screen)
{
	SDL_Flip(screen);
}

void background::setFree()
{
	SDL_FreeSurface(this->bckgrnd);
}